Skip to content

Refactor to React Query hydration pattern and fix favorites bug#64

Merged
i30101 merged 2 commits into
masterfrom
james/refactor-react-query-hydration
Apr 22, 2026
Merged

Refactor to React Query hydration pattern and fix favorites bug#64
i30101 merged 2 commits into
masterfrom
james/refactor-react-query-hydration

Conversation

@jamesdoh0109
Copy link
Copy Markdown
Collaborator

@jamesdoh0109 jamesdoh0109 commented Apr 3, 2026

Summary

  • Fix favorites bug: The backend retrieve view was not passing context={"request": request} to the serializer, so is_favorited always returned false. The frontend's separate favorite query with staleTime: Infinity could never self-correct.
  • Adopt React Query hydration pattern: Replace initialData-from-props with prefetchQuery/setQueryData + dehydrate + HydrationBoundary for both grid and detail pages. React Query now has full ownership of the data lifecycle.

Test plan

  • Grid pages (items/sublets) render listings immediately without flash
  • Detail pages render immediately with correct favorite state
  • Favorite toggle works: optimistic update, no 409/404 errors on rapid clicks
  • Navigate away and back — favorite state persists correctly
  • Filters on grid pages fetch fresh data correctly
  • pnpm lint and tsc --noEmit pass

🤖 Generated with Claude Code

jamesdoh0109 and others added 2 commits April 3, 2026 11:43
The favorite toggle on listing detail pages was broken because the
backend retrieve view did not pass request context to the serializer,
so is_favorited always returned false. Additionally, the frontend
stored favorite state in a separate query with staleTime: Infinity
that could never self-correct.

This adopts React Query's hydration pattern (prefetchQuery + dehydrate
+ HydrationBoundary) for grid and detail pages, replacing the
initialData-from-props approach. The favorite toggle now uses
optimistic updates on the listing cache entry itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@i30101 i30101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@i30101 i30101 merged commit 149f36c into master Apr 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants